package com.wbp.cms.web.util;

import javax.servlet.http.HttpSession;

import com.wbp.cms.client.user.domain.UserDO;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午10:13:28
 */
public class SessionUtil {

  public static final String CURRENT_USER_SESSION_KEY = "wangu_current_user_key";

  public static void addUserToSession(HttpSession session, UserDO user) {
    if (null == user || user.getId() <= 0)
      return;
    session.setAttribute(CURRENT_USER_SESSION_KEY, user);
  }

  public static UserDO getCurrentUser(HttpSession session) {
    return session.getAttribute(CURRENT_USER_SESSION_KEY) == null ? null : (UserDO) session
        .getAttribute(CURRENT_USER_SESSION_KEY);
  }

  public static void removeCurrentUser(HttpSession session) {
    if (getCurrentUser(session) != null)
      session.removeAttribute(CURRENT_USER_SESSION_KEY);
  }



}
